I am using DOORS 9.2, I need find out the OLE type.
This is what I am trying in my DXL to get the OLE type.
I think that oleGet will return OLE application type, such as "Excel", "Word", "PDF", etc....
{auto_obj = oleGetAutoObject(obj)} always return null.
I just need to find out which application the OLE belongs to and export the OLE to file system.
Here is my code:
{
#include <utils/ole.inc>
Object obj
OleAutoObj auto_obj
string val = ""
bool results
Module m = current Module
for obj in m do {
if (oleIsObject obj){
auto_obj = oleGetAutoObject(obj)
if (auto_obj != null)
{
val = oleGet(auto_obj,"Application",results)
if (null results)
{ print (identifier obj) " has OLE Object with -" val "-\n" }
else { print (identifier obj) " has OLE Object with -" val "- and -" results "-\n" }
} else { print (identifier obj) " has OLE Object but did not get it\n" }
} // end oleIsObject
} // end for
}
aakhws - Sat Apr 24 16:13:35 EDT 2010 |
|
Re: select an OLE Mathias Mamsch - Sun Apr 25 07:08:17 EDT 2010
The only way I know of to do this is to parse the rtf of the OLE object.
The code below might get you going. Regards, Mathias
Mathias Mamsch, IT-QBase GmbH
Consultant Requirement Engineering and DOORS
Object o = current
Buffer b = create()
b = richTextWithOle o."Object Text"
string reHeader = "{\\\\object\\\\objemb{\\\\\\*\\\\objclass ([^}]+)}"
string picHeader = "{\\\\pict\\\\([^\\\\]+)"
Regexp reOle = regexp reHeader
Regexp rePic = regexp picHeader
Regexp reOlePicFind = regexp "{\\\\(object|pict)"
// Determine the right regular expression to use ...
reOlePicFind b
// print "Looking in Buffer:" (tempStringOf b) "\n"
string type = b[match 1]
if (type == "pict") expr = rePic else expr = reOle
if (expr b) {
val = b [match 1]
print "Class: " val "\n"
} else {
print "No OLE found!"
}
|
|
Re: select an OLE deniseml - Tue Apr 10 13:26:46 EDT 2012 Mathias Mamsch - Sun Apr 25 07:08:17 EDT 2010
The only way I know of to do this is to parse the rtf of the OLE object.
The code below might get you going. Regards, Mathias
Mathias Mamsch, IT-QBase GmbH
Consultant Requirement Engineering and DOORS
Object o = current
Buffer b = create()
b = richTextWithOle o."Object Text"
string reHeader = "{\\\\object\\\\objemb{\\\\\\*\\\\objclass ([^}]+)}"
string picHeader = "{\\\\pict\\\\([^\\\\]+)"
Regexp reOle = regexp reHeader
Regexp rePic = regexp picHeader
Regexp reOlePicFind = regexp "{\\\\(object|pict)"
// Determine the right regular expression to use ...
reOlePicFind b
// print "Looking in Buffer:" (tempStringOf b) "\n"
string type = b[match 1]
if (type == "pict") expr = rePic else expr = reOle
if (expr b) {
val = b [match 1]
print "Class: " val "\n"
} else {
print "No OLE found!"
}
I've used Mathias' dxl code to determine the type of OLE embedded in current Object. In my case the OLE is an Excel file. Now, I need to extract the content from the OLE and create an Excel file with that content. Any idea how to do this? Thanks
|
|
Re: select an OLE Mathias Mamsch - Mon Apr 16 05:20:03 EDT 2012 deniseml - Tue Apr 10 13:26:46 EDT 2012
I've used Mathias' dxl code to determine the type of OLE embedded in current Object. In my case the OLE is an Excel file. Now, I need to extract the content from the OLE and create an Excel file with that content. Any idea how to do this? Thanks
Well the easy way to do this, is use "copy/paste" from DOORS as all the exporters do, if you use COM automation for generating your Excel file. The ultra hard way would be to try to try to create an Excel file from scratch, directly embedding the OLE data into it. For this you should choose the easiest file format (maybe do not take the BIFF format :-), look for current XML formats for example). But I would consider that to hardcore for an excel export. What are you trying to do?
Regards, Mathias
Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS
|
|
Re: select an OLE deniseml - Mon Apr 16 07:19:07 EDT 2012 Mathias Mamsch - Mon Apr 16 05:20:03 EDT 2012
Well the easy way to do this, is use "copy/paste" from DOORS as all the exporters do, if you use COM automation for generating your Excel file. The ultra hard way would be to try to try to create an Excel file from scratch, directly embedding the OLE data into it. For this you should choose the easiest file format (maybe do not take the BIFF format :-), look for current XML formats for example). But I would consider that to hardcore for an excel export. What are you trying to do?
Regards, Mathias
Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS
Mathias, Thank you for your help. Here goes on the details:
I am writing a script that takes a selected pair of modules (with well defined structure, i.e. attributes and section headings) and creates an XML file based on a specific schema. The last (most difficult) part of the script is to capture OLEs in the XML which must be formatted in Base-64. I have the code working for .PNG OLEs. For PNG it basically writes the OLE to a temporary file errmess = exportPicture(ole,tempFilename, formatPNG), then reads the temporary file Stream inStream = read binary tempFileName, then converts the inStream to Base-64 encoding and writes it to the XML file.
BUT we need to be able to process Excel files on the receiving end (another database tool). I used your code to help figure out whether the OLE application is Excel, but the only way to process the Excel (that I can figure out) is to write the Excel to a temporary xls file and proceed as with the read binary. An 'oleActiviate' brings up the Excel OLE in Excel nicely but I can't figure out a way to write it to a file for reading in binary later (without involving the user typing in Save As...). Ideas? Thanks.
|
|
Re: select an OLE Mathias Mamsch - Tue Apr 17 06:45:38 EDT 2012 deniseml - Mon Apr 16 07:19:07 EDT 2012
Mathias, Thank you for your help. Here goes on the details:
I am writing a script that takes a selected pair of modules (with well defined structure, i.e. attributes and section headings) and creates an XML file based on a specific schema. The last (most difficult) part of the script is to capture OLEs in the XML which must be formatted in Base-64. I have the code working for .PNG OLEs. For PNG it basically writes the OLE to a temporary file errmess = exportPicture(ole,tempFilename, formatPNG), then reads the temporary file Stream inStream = read binary tempFileName, then converts the inStream to Base-64 encoding and writes it to the XML file.
BUT we need to be able to process Excel files on the receiving end (another database tool). I used your code to help figure out whether the OLE application is Excel, but the only way to process the Excel (that I can figure out) is to write the Excel to a temporary xls file and proceed as with the read binary. An 'oleActiviate' brings up the Excel OLE in Excel nicely but I can't figure out a way to write it to a file for reading in binary later (without involving the user typing in Save As...). Ideas? Thanks.
This will give you a clue about how to get the Excel Application Object from the activated OLE:
http://www.ibm.com/developerworks/forums/click.jspa?searchID=-1&messageID=14610983
Then you can save the Excel file using normal calls (multiple examples in forum, search for "excel saveas").
However I am not sure why you are trying to Process each kind of OLE object differently? Did you ever consider just copying the OLE objects to a scrap file (regardless of what kind of application it is), read that scrap file and embed it in your XML. Sounds like a much simpler idea. I know I have seen code for this somewhere here, utilizing FileSystemObject or something, but I cannot find it at the moment.
Regards, Mathias
Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS
|
|
Re: select an OLE deniseml - Wed Apr 18 10:26:06 EDT 2012 Mathias Mamsch - Tue Apr 17 06:45:38 EDT 2012
This will give you a clue about how to get the Excel Application Object from the activated OLE:
http://www.ibm.com/developerworks/forums/click.jspa?searchID=-1&messageID=14610983
Then you can save the Excel file using normal calls (multiple examples in forum, search for "excel saveas").
However I am not sure why you are trying to Process each kind of OLE object differently? Did you ever consider just copying the OLE objects to a scrap file (regardless of what kind of application it is), read that scrap file and embed it in your XML. Sounds like a much simpler idea. I know I have seen code for this somewhere here, utilizing FileSystemObject or something, but I cannot find it at the moment.
Regards, Mathias
Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS
Thanks for the link about recognizing and activating Excel OLEs.
To answer your question: I am processing each OLE differently (or at least Excel vs. all other types) because we need to be able to activate the OLE int he remote database using Excel. The XML needs to be Base64. The only way I can figure out how to convert to Base64 (for the XML output)is by reading from a binary file. I don't know how to read an OLE one char at a time to do the conversion to Base64 without writing to a temp file, so I'm writing it to a binary file. For non-Excel OLEs I am using "errmess = exportPicture(ole,filename , formatPNG)" where formatPNG is the only option available. If I use this method on an Excel OLE, the information arrives in the remote database as a picture. The user wants the file on the remote database side to be editable in Excel. So, I am attempting to save the Excel OLE into an Excel file and then do a read binary (Stream inStream = read binary inFile) for conversion to Base64. Yes, it is a very clumsy method (and it requires the user to do a Save As to a specific file name)- can't figure another way to do it.
|
|
Re: select an OLE Karray - Tue Sep 03 08:56:16 EDT 2013 deniseml - Wed Apr 18 10:26:06 EDT 2012
Thanks for the link about recognizing and activating Excel OLEs.
To answer your question: I am processing each OLE differently (or at least Excel vs. all other types) because we need to be able to activate the OLE int he remote database using Excel. The XML needs to be Base64. The only way I can figure out how to convert to Base64 (for the XML output)is by reading from a binary file. I don't know how to read an OLE one char at a time to do the conversion to Base64 without writing to a temp file, so I'm writing it to a binary file. For non-Excel OLEs I am using "errmess = exportPicture(ole,filename , formatPNG)" where formatPNG is the only option available. If I use this method on an Excel OLE, the information arrives in the remote database as a picture. The user wants the file on the remote database side to be editable in Excel. So, I am attempting to save the Excel OLE into an Excel file and then do a read binary (Stream inStream = read binary inFile) for conversion to Base64. Yes, it is a very clumsy method (and it requires the user to do a Save As to a specific file name)- can't figure another way to do it.
Hi Deniseml,
Can you attach me the code doing this: """and then do a read binary (Stream inStream = read binary inFile) for conversion to Base64. """"
Because I don't know how to convert the contain of a stream to a BASE64.
Thank you.
|
|
Re: select an OLE GregM_dxler - Wed Sep 04 09:39:27 EDT 2013 Mathias Mamsch - Sun Apr 25 07:08:17 EDT 2010
The only way I know of to do this is to parse the rtf of the OLE object.
The code below might get you going. Regards, Mathias
Mathias Mamsch, IT-QBase GmbH
Consultant Requirement Engineering and DOORS
Object o = current
Buffer b = create()
b = richTextWithOle o."Object Text"
string reHeader = "{\\\\object\\\\objemb{\\\\\\*\\\\objclass ([^}]+)}"
string picHeader = "{\\\\pict\\\\([^\\\\]+)"
Regexp reOle = regexp reHeader
Regexp rePic = regexp picHeader
Regexp reOlePicFind = regexp "{\\\\(object|pict)"
// Determine the right regular expression to use ...
reOlePicFind b
// print "Looking in Buffer:" (tempStringOf b) "\n"
string type = b[match 1]
if (type == "pict") expr = rePic else expr = reOle
if (expr b) {
val = b [match 1]
print "Class: " val "\n"
} else {
print "No OLE found!"
}
Hi,
The oleGetAutoObject won't work until you have already activate the ole. This is how I find the application.
sError = oleOpen(o1, c1, 0) //activate first OLE in the column of the attribute, undocumented dxl command
// sError = oleActivate(o1, c1, 0) //activate first OLE in the column of the attribute. This command doesn't work
if (null sError) {
bIsActivated = true
}
else { //error activating OLE
if (DEBUG) print "Error in OLE activation here. DOORS limitation. Error message=" sError "\n"
bIsActivated = false
oleDeactivate(o1, c1, 0)
sError = "OID:" sObjId ", Attribute:" sAttr ", Unable to activate OLE: DOORS limitation.\n"
if (DEBUG) print "New error message=" sError "\n"
}
if (bIsActivated) {
//OLE is activated now, so go get the automation interface object
objDoc = oleGetAutoObject(o1, c1, 0) //undocumented dxl command
if (null objDoc) {
//Something is wrong getting OLE handle
objDoc = oleGetAutoObject(o1) //try this then
if (null objDoc) {
if (DEBUG) print "Error getting document handle.\n"
oleCloseAutoObject (objDoc)
oleDeactivate(o1, c1, 0)
bIsActivated = false
sError = "OID:" sObjId ", Attribute:" sAttr ", Unable to get document handle for OLE.\n"
}
}
else { //got automation interface handle okay
//Go fetch the application to use of the OLE
sErr = oleGet(objDoc, "Application", objApp)
if (!null sErr) {
//error in getting application defined for OLE
oleCloseAutoObject (objApp)
oleCloseAutoObject (objDoc)
oleDeactivate(o1, c1, 0)
bIsActivated = false
sError = "OID:" sObjId ", Attribute:" sAttr ", Cannot get application info for OLE.\n"
}
if (null objApp) {
//no application defined for OLE
oleCloseAutoObject (objApp)
oleCloseAutoObject (objDoc)
oleDeactivate(o1, c1, 0)
bIsActivated = false
sError = "OID:" sObjId ", Attribute:" sAttr ", Unable to get application for activated document.\n"
}
}
}
if (bIsActivated) {
//Get application name for OLE
oleGet(objApp, "Name", sName)
//Word OLE
if (matches("Word", sName)) {
//put word commands here using oleGet and olePut
}
//Excel OLE
else if (matches("Excel", sName)) {
//put excel commands here using oleGet and olePut
}
}
If your OLEs is in the main column, you can simplify it by using the oleActivate(o1) command.
Hope this helps,
Greg
|
|